package com.example.facecomparedemo.CodeFilter;



import jdk.nashorn.internal.runtime.CodeInstaller;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(urlPatterns = "/api/*")
public class TokenFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request1 = (HttpServletRequest) request;//向下转型
        String token = request1.getHeader("token");//接受请求头中的token
        ///验证token
//        boolean res = JWTUtil.verify(token);
//        if(res){//token验证成功.继续向后执行
//            chain.doFilter(request,response);
//        }else{//token  验证失败向前发送401
//            Result result = new Result(401,"认证失败",null);
//            response.getWriter().print(new ObjectMapper().writeValueAsString(result));
//        }
        System.out.println("token过滤器");
    }
}

